local SkillNameFloatView = class("SkillNameFloatView",function() return display.newNode() end )

local NodePool = custom.NodePool:getInstance()

local OriginScale = nil

function SkillNameFloatView.create()
    return NodePool:getByKey("SkillNameFloatView") or SkillNameFloatView.new()
end

function SkillNameFloatView:ctor()
    local node = cc.CSLoader:createNode(Res.BattleSkillNameEffect)
    display.setCascadeOpacityEnabled(node,true)

    local teamTextView = node:findChild("team/name")
    teamTextView:setVisible(false)
    self._teamTextView = teamTextView
    local foeTextView = node:findChild("foe/name")
    foeTextView:setVisible(false)
    self._foeTextView = foeTextView
    self._node = node
    self:addChild(node)
    if not OriginScale then
        OriginScale = node:getScale()
    end
end

function SkillNameFloatView:play(isSelfTeam,name,isComboSkill)

    local teamTextView = self._teamTextView
    local foeTextView = self._foeTextView
    
    teamTextView:setVisible(false)
    foeTextView:setVisible(false)

    local displayView = isSelfTeam and teamTextView or foeTextView
    displayView:setVisible(true)
    displayView:setString(name)


    local node = self._node
    if isComboSkill then
        node:setScale(OriginScale*1.3)
    else
        node:setScale(OriginScale)
    end
    node:setVisible(true)

    local timeline = node:getTimeline()
    timeline:gotoFrameAndPlay(0,false)
    timeline:setLastFrameCallFunc(function()
        if not cc.isDead(node) then
            node:setVisible(false)
        end
        if not cc.isDead(self) then
            NodePool:put(self,"SkillNameFloatView")
            self:removeFromParent(false)
        end
    end)
    return timeline:getDuration()
end


return SkillNameFloatView